{extend name="index/index" /}
{block name="main"}
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="http://cdn.bootcss.com/tinymce/4.4.3/tinymce.min.js"></script>
<script>tinymce.init({ selector:'textarea' });</script>

<div class="content-page">

    <div class="content">

        <div class="page-heading">
            <h1><i class='fa fa-table'></i>文章管理</h1>
            <h3>添加文章</h3></div>

        <div class="row">

            <div class="col-md-12">
                <div class="widget"  >
                    <div class="widget-header transparent" style="margin-bottom:30px;">
                        <h2><strong>Sortable</strong> Table</h2>

                    </div>
                    <div class="widget-content">
                    <form name="form1" id="form1" class="form-horizontal" action="{:url('admin/article/save')}" method="post" enctype="multipart/form-data" >

                        <table class="table">
                            
                            <tr>
                                <th>文章名称</th>
                                <td><input type='text' name='artname' id='articlename' /></td>

                            </tr>
                            <tr>
                                <th>文章类别 </th>
                                <td>
                                    <select class="form-control" name='column_id' style="width:180px;">
                                        {volist name="list" id="v"}
                                      <option value="{$v.column_id}">{$v.colname}</option>
                                        {/volist}
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <th>上传图片</th>
                                <td><input type='file'  name="photo" id="photo" /></td>

                            </tr>

                        </table>
                        



                        <textarea id="elm1" ></textarea>
                        <input type='hidden' name='artcontent' value='' id='inputconc' placeholder=""></input>
                        <input type='hidden' name='arttext' value='' id='inputcont' placeholder=""></input>
                        <input type='hidden' name='picname' value='' id='result' placeholder=""></input>
                        <!-- <input type="button" name="b1" value="上传图片" onclick="fsubmit()" class="btn btn-warning"> -->
                        <input  type="button" onclick= "doy()" value='发布' class="btn btn-info"/> 
                        <!-- <button type="button" class="btn btn-success" onclick="check()">发布</button> -->
                    </form>
    
                </div>

            </div>
        </div>


    
    </div>

   

</div>

<script>
    function doy(){
        var tmpc= tinymce.get('elm1').getContent();      //此函数可获得编辑框内容   
        var tmpt= tinymce.get('elm1').getContent( { 'format' : 'text' } );      //此函数可获得纯文本  
        document.getElementById('inputconc').value = tmpc;
        document.getElementById('inputcont').value = tmpt;

        toastr.options = {
        closeButton: true,// 是否显示关闭按钮
        progressBar: true,// 实现显示计时条
        timeOut: "2000",// 自动关闭时间
        positionClass: "toast-top-right"// 提示位置
        // positionClass: "toast-top-full-width"// 提示位置
        // toast-top-full-width 顶端，宽度铺满整个屏幕
        // toast-top-right  顶端右边
        };




        function check()
        {
            // var artName = document.getElementById('articlename').value;
            var artName = $('#articlename').val();
            var artCon = tinymce.get('elm1').getContent();
            if(artName.length==0 || artCon.length==0){  

                toastr.error('文章名或者内容为空');

            }else
            {


                var data = new FormData($('#form1')[0]);
                $.ajax({
                    url: '/admin/article/server',
                    type: 'POST',
                    data: data,
                    dataType: 'JSON',
                    cache: false,
                    processData: false,
                    contentType: false
                }).done(function(ret){
                    if(ret['isSuccess']){
                        // $('#result').html(ret['photo'] );
                        document.getElementById('result').value = ret['photo'];
                        toastr.success('添加文章成功');
                        setTimeout(function fun(){
                            $('#form1').submit();
                        },2000)
                        // alert('上传成功');

                    }else{

                        toastr.success('添加纯文章成功');
                        setTimeout(function fun(){
                            $('#form1').submit();
                        },2000)
                        // alert('提交失敗');
                    }
                });


            }  
        }
        check();


        
    }
  </script>

  <!-- <script type="text/javascript">


    toastr.options = {
    closeButton: true,// 是否显示关闭按钮
    progressBar: true,// 实现显示计时条
    timeOut: "3000",// 自动关闭时间
    positionClass: "toast-bottom-left"// 提示位置
    // positionClass: "toast-top-full-width"// 提示位置
    // toast-top-full-width 顶端，宽度铺满整个屏幕
    // toast-top-right  顶端右边
    };


    function check()
    {
        // var artName = document.getElementById('articlename').value;
        var artName = $('#articlename').val();
        var artCon = tinymce.get('elm1').getContent();
        if(artName.length==0 || artCon.length==0){  

            toastr.error('文章名或者内容为空');

        }else
        {


            var data = new FormData($('#form1')[0]);
            $.ajax({
                url: '/admin/article/server',
                type: 'POST',
                data: data,
                dataType: 'JSON',
                cache: false,
                processData: false,
                contentType: false
            }).done(function(ret){
                if(ret['isSuccess']){
                    // $('#result').html(ret['photo'] );
                    document.getElementById('result').value = ret['photo'];
                    toastr.success('添加文章成功');
                    setTimeout(function fun(){
                        $('#form1').submit();
                    },2000)
                    // alert('上传成功');

                }else{

                    toastr.success('添加纯文章成功');
                    setTimeout(function fun(){
                        $('#form1').submit();
                    },2000)
                    // alert('提交失敗');
                }
            });


        }  
    }

    // function fsubmit(){
    //     var data = new FormData($('#form1')[0]);
    //     $.ajax({
    //         url: '/admin/article/server',
    //         type: 'POST',
    //         data: data,
    //         dataType: 'JSON',
    //         cache: false,
    //         processData: false,
    //         contentType: false
    //     }).done(function(ret){
    //         if(ret['isSuccess']){
    //             // $('#result').html(ret['photo'] );
    //             document.getElementById('result').value = ret['photo'];
    //             toastr.success('添加文章成功');
    //             setTimeout(function fun(){
    //                 $('#form1').submit();
    //             },2000)
    //             // alert('上传成功');

    //         }else{

    //             toastr.success('添加纯文章成功');
    //             setTimeout(function fun(){
    //                 $('#form1').submit();
    //             },2000)
    //             // alert('提交失敗');
    //         }
    //     });
       
    // }
  </script> -->

{/block}